package org.liuhy.line
{
	import flash.geom.Point;
	
	import mx.collections.ArrayCollection;
	import mx.events.DragEvent;
	
	import org.liuhy.node.FlowNode;
	import org.liuhy.node.focus.FocusNode;
	import org.liuhy.utils.LineUtils;
	
	public class StraightLine extends AbstractLine
	{
		public function StraightLine(p_x1:int,p_y1:int,p_x2:int,p_y2:int,p_cLine:CLine)
		{
			super(p_x1,p_y1,p_x2,p_y2,p_cLine);
		}
		//画线
		override public function draw():void{
			this.fromLineNode.x	=x1-5;
			this.fromLineNode.y	=y1-5;
			this.fromLineNode.setStyle("borderColor",this.lineNodeBorderColor);
			this.fromLineNode.setStyle("backgroundColor",this.lineNodeBackgroundColor);
						
			graphics.clear();			
			graphics.beginFill(0x000000,0);
			graphics.lineStyle(1, this.lineColor);
			graphics.moveTo(x1,y1);
			graphics.lineTo(x2, y2);
			graphics.endFill();
			if(null!=this._arrow){
				try{
					this.removeChild(this._arrow);
					this.removeChild(this.arrowLineNode);
				}catch(e:Error){
					
				}
			}
			this._arrow 		= 	new Arrow();
			var toPoint:Point	=	new Point(this.x2,this.y2);
			var fromPoint:Point = 	new Point(this.x1,this.y1);
            _arrow.fromPoint	=	fromPoint;
            _arrow.toPoint		=	toPoint;
            _arrow.draw();
            this.addChild(_arrow);
            //末端增加调整方块
            arrowLineNode = new ArrowLineNode(this.x2,this.y2);
            this.arrowLineNode.setStyle("borderColor",this.lineNodeBorderColor);
			this.arrowLineNode.setStyle("backgroundColor",this.lineNodeBackgroundColor);
            arrowLineNode.visible = true;
			this.addChild(arrowLineNode);
		}
		override public function setFocusVisible(p_bool:Boolean):void{
			var _arrayLine:ArrayCollection = LineUtils.getAllLine(this);
			for(var j:int=0;j<_arrayLine.length;j++){
				var _line:AbstractLine = _arrayLine.getItemAt(j) as AbstractLine;
				_line.fromLineNode.visible = p_bool;
//				_line.midLineNode.visible  = p_bool;
				if(null!=_line.arrowLineNode){
					_line.arrowLineNode.visible = p_bool;
				}
			}
		}
		//移动fromNode节点调整线;
		override public function fromNodeAdjustLine(p_event:DragEvent):void{
			var _cLine:CLine = this.parent as CLine;
			this.x1 = p_event.localX-_cLine.x
			this.y1 = p_event.localY-_cLine.y;
			this.draw();
		}
		//移动中间节点调整线;		
		override public function midNodeAdjustLine(p_event:DragEvent):void{
		}
		//移动箭头节点调整线;
		override public function arrowNodeAdjustLine(p_event:DragEvent):void{
			var _cLine:CLine = this.parent as CLine;
			this.x2 = p_event.localX-_cLine.x
			this.y2 = p_event.localY-_cLine.y;
			this.draw();
		}
		override public function focusNodeDropArrowLine(p_focusNode:FocusNode):void{
			var _flowNode:FlowNode = p_focusNode.parent as FlowNode;
			var _cLine:CLine = this.parent as CLine;
			this.x2 =  p_focusNode.x+_flowNode._x-_cLine.x;
			this.y2 =  p_focusNode.y+_flowNode._y-_cLine.y;
			this.in_flowFocusNode = p_focusNode;
			_flowNode.addInLine(this);
			this.draw();
		}
		override public function focusNodeDropFromLine(p_focusNode:FocusNode):void{
			var _flowNode:FlowNode = p_focusNode.parent as FlowNode;
			var _cLine:CLine = this.parent as CLine;
			this.x1 =  p_focusNode.x+_flowNode._x-_cLine.x;
			this.y1 =  p_focusNode.y+_flowNode._y-_cLine.y;
			this.out_flowFocusNode = p_focusNode;
			_flowNode.addOutLine(this);
			this.draw();
		}			
		override public function focusNodeAdjustArrowLine(p_focusNode:FocusNode):void{
			var _flowNode:FlowNode = p_focusNode.parent as FlowNode;
			var _cLine:CLine = this.parent as CLine;
			this.x2 =  p_focusNode.x+_flowNode._x-_cLine.x;
			this.y2 =  p_focusNode.y+_flowNode._y-_cLine.y;
			this.draw();
		}
		override public function focusNodeAdjustFromLine(p_focusNode:FocusNode):void{
			var _flowNode:FlowNode = p_focusNode.parent as FlowNode;
			var _cLine:CLine = this.parent as CLine;
			this.x1 =  p_focusNode.x+_flowNode._x-_cLine.x;
			this.y1 =  p_focusNode.y+_flowNode._y-_cLine.y;
			this.draw();
		}		
	}
}